import { css_wind_light } from '../../../../../global/element/DataDefine/sourceData';
import { domTree } from '../../../../../global/element/domTree';
import {
  normalizeContainer,
  packNode,
} from '../../../../../global/element/Func';
import {
  math_random_digits,
  removeObjectOnlyPushSet,
} from '../../../../../global/Func/uniFunc/Func';
import {
  css_focusDisplay_container,
  css_focusDisplay_default,
} from '../../../DataDefine/sourceData';
import {
  focueDisplay_dom_id_prefix,
  focusDisplay_id_split,
  win_static_focusDisplay,
  win_static_focusDisplay_namespace,
} from '../DataDefine/sourceData';
import { focusDisplay_operate } from './cla_focusDisplay_operate/cla_focusDisplay_operate';
import { uni_static_focusDisplayEl_dataMana } from './cla_uni_static_focusDisplayEl_dataMana';

const uni_static_focusDisplayElTag = 'uni_static_focusDisplayEl';

class uni_static_focusDisplayEl extends uni_static_focusDisplayEl_dataMana {
  get [Symbol.toStringTag]() {
    return uni_static_focusDisplayElTag;
  }

  constructor() {
    super();
  }

  /**
   * 命名 空间
   * @type {string}
   */
  spacename;

  /**
   * 删除 window 上的 信息
   */
  destroy() {
    removeObjectOnlyPushSet(
      window[win_static_focusDisplay],
      this.spacename,
      true,
      win_static_focusDisplay_namespace
    );
  }

  /**
   * 创建 一个 隐藏的 焦点元素
   * @returns {focusDisplay_operate}
   */
  create_new_focusDisplay_dom() {
    let a = {
      tag: 'dialog',
      attriKey: ['id'],
      class: [css_focusDisplay_default, css_wind_light],
      id: this.random_new_id(),
      queue: ['b'],
      b: {
        tag: 'div',
        class: [css_focusDisplay_container],
      },
    };

    let dom = domTree(a);

    this[dom.id] = new focusDisplay_operate(dom);

    packNode(document.body, dom, true, normalizeContainer('app'));
    return this[dom.id];
  }

  /**
   * 获取 或 创建 当前 最后一个创建 的 dialog 元素
   * @returns {focusDisplay_operate}
   */
  getOrCreate_focusDisplay_dom() {
    let dom = this.get_cur_dialog_dom();
    if (![undefined, null].includes(dom)) {
      return dom;
    }
    return this.create_new_focusDisplay_dom();
  }

  /**
   * 新生成 一个 id
   */
  random_new_id() {
    let random_id_suffix = math_random_digits(4);
    let id =
      focueDisplay_dom_id_prefix + focusDisplay_id_split + random_id_suffix;

    this.push_id(id);

    return id;
  }
}

export { uni_static_focusDisplayEl };
